﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Linkmeme.Models;

namespace Linkmeme.Views.User
{
    public partial class SearchResult : ViewPage<List<Linkmeme.Models.User>>
    {
        private List<Linkmeme.Models.User> friends;
        private LinkmemeDataContext dataContext = new LinkmemeDataContext();
        protected bool IsFriend(Linkmeme.Models.User user)
        {

            if (User.Identity.IsAuthenticated)
            {
                if (friends == null)    
                    friends = dataContext.Users.Single(u => u.UserName == User.Identity.Name).Friends.ToList();
                if (friends.Exists(f=>f.UserName == user.UserName))
                    return true;
            }
            return false;
        }
    }
}
